/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/


// TODO 将来放开
import request from '@/utils/request';
import { IAntdTableParams, IPromiseListApi } from '@/types/type';
import { IOperationItem, IOperationList } from '@/types/operationHistory';
import { AntdFormUtils } from 'ahooks/es/useAntdTable/types';
// import { getDateTime } from '@/utils/soa/utils';
import base from './base';
import moment from "moment";

// 管理后台操作日志列表
export async function getOperationList(
  { current, pageSize }: IAntdTableParams,
  formData: AntdFormUtils,
) {
  const { keyword, datetime } = formData;
  const {
    data
  } = await request.get<IPromiseListApi<IOperationList>>(
    `/${base.API}/ms-soa-operationlog/${base.VERSION}/admin/operation/_list`,
    {
      params: {
        createNickName: keyword,
        createTimeStart: datetime?.[0]?moment(datetime?.[0])?.startOf('day')?.toISOString():undefined,
        createTimeEnd: datetime?.[1]?moment(datetime?.[1])?.endOf('day')?.toISOString():undefined,
        pagesize: pageSize,
        current,
      },
    },
  );
  return {
    list: data?.itemSize
      ? data?.dataList.map((item: IOperationItem, index: number) => ({
          ...item,
          index: index + 1 + (current - 1) * pageSize,
        }))
      : [],
    total: data?.pageCount,
  };
}
